package com.hui.dbmigrator.service;

import com.hui.dbmigrator.handler.DatabaseHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

// DatabaseService.java
@Service
@RequiredArgsConstructor
public class DatabaseService {

    private final List<DatabaseHandler> handlers;

    public DatabaseHandler getHandler(String dbType) {
        return handlers.stream()
                .filter(h -> h.getDatabaseType().equalsIgnoreCase(dbType))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException(
                        "No handler found for database type: " + dbType));
    }

    public List<String> getSupportedDatabases() {
        return handlers.stream()
                .map(DatabaseHandler::getDatabaseType)
                .collect(Collectors.toList());
    }
}
